Operator Precedence


Operator precedence determines the order in which operators are evaluated in expressions. Operators with higher precedence are evaluated before operators with lower precedence.

Operator Precedence Table

Here is a table of JavaScript operators listed in order of precedence (from highest to lowest):

  1. Grouping: ()
  2. Member Access: obj.property
  3. Function Call: myFunction()
  4. New: new
  5. Postfix Increment/Decrement: ++ --
  6. Logical NOT: !
  7. Bitwise NOT: ~
  8. Unary Plus/Minus: + -
  9. Multiplication/Division/Modulus: * / %
  10. Addition/Subtraction: + -
  11. Bitwise Shift: << >> >>>
  12. Relational: < > <= >=
  13. Equality: == != === !==
  14. Bitwise AND: &
  15. Bitwise XOR: ^
  16. Bitwise OR: |
  17. Logical AND: &&
  18. Logical OR: ||
  19. Conditional (Ternary): ? :
  20. Assignment: = += -= *= /= %= &= ^= |= <<= >>= >>>=
  21. Comma: ,

Examples

Here are some examples demonstrating operator precedence in JavaScript:

console.log(3 + 4 * 2); // 11 (Multiplication before addition)
console.log((3 + 4) * 2); // 14 (Grouping changes the order)
console.log(10 > 5 && 5 < 3); // false (Relational before logical AND)
console.log(10 > (5 && 5 < 3)); // true (Grouping changes the order)

For more detailed information, you can check out resources like MDN Web Docs and W3Schools.